#!/usr/bin/env python3
from flask import Flask
from flask import request
from flask import make_response
from flask import url_for
from flask import render_template

from flask_sqlalchemy import SQLAlchemy


app = Flask(__name__)

app.config['SQLAlchemy_DATABASE_URI'] = \
"mysql ://xlb:123123@localhost/test/aa"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=True
db = SQLAlchemy(app)


#@app.route('/')
#def hello_world():
#    return '<h1>Hello World</h1>'

#@app.route('/test',methods=['POST'])
#def test():
#    return 'post user'

@app.route('/userid',methods=['POST'])
def show_userid():
    return 'user name:{0},passwd is {1}'.format(request.form['uid'],request.form['pwd'])
#app.add_url_rule('/userid/<int:user_id>',view_func=show_userid)

@app.route("/")
def v_index():
    rsp = make_response('go<a href="%s">page2</a>'%url_for('v_page2'))
    rsp.set_cookie('user','aaa')
    return rsp 
@app.route('/page2')
def v_page2():
    user = request.cookies['user']
    return 'you are %s'% user


'''def item():
    return """<html>
<head>
	<title>login page</title>
</head>
<body>
	<form method="POST" action="/login">
	<input type="text" name="uid">
	<input type="password" name="pwd">
	<input type="submit" name="login">

	</form>
</body>
</html>"""
'''
@app.route('/login')
def hh():
    #return 'you name is {}'.format(request.form['username'])
    return render_template('login.html')



if __name__ == '__main__':
    app.run(host='0.0.0.0',port=808,debug=True,threaded=True)
